package com.zsrd.self.controller;

import com.zsrd.self.base.Result;
import com.zsrd.self.entity.Datas;
import com.zsrd.self.service.DataService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/data")
@Slf4j
public class DataController {


    @Autowired
    DataService dataService;

    @PostMapping("/data")
    public Result<List<Map>> datas() {
        ArrayList<Map> list1 = new ArrayList<>();
        List<Datas> list = dataService.list();
        HashMap<String, String> map = new HashMap<>();
        for (Datas data : list) {
            map.put(data.getCode() , data.getValue());
        }
        list1.add(map);
        return Result.success(list1);
    }
}
